/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AdminConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.cs.account.AutoProvisionThread;
/*    */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import com.zimbra.soap.admin.message.AutoProvTaskControlRequest.Action;
/*    */ import com.zimbra.soap.admin.message.AutoProvTaskControlResponse.Status;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class AutoProvTaskControl
/*    */   extends AdminDocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 37 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 38 */     checkRight(zsc, context, null, AdminRight.PR_SYSTEM_ADMIN_ONLY);
/*    */     
/* 40 */     AutoProvTaskControlRequest.Action action = AutoProvTaskControlRequest.Action.fromString(request.getAttribute("action"));
/*    */     
/*    */     AutoProvTaskControlResponse.Status result;
/* 43 */     switch (action) {
/*    */     case start: 
/* 45 */       result = handleStart();
/* 46 */       break;
/*    */     case status: 
/* 48 */       result = handleStatus();
/* 49 */       break;
/*    */     case stop: 
/* 51 */       result = handleStop();
/* 52 */       break;
/*    */     default: 
/* 54 */       throw ServiceException.INVALID_REQUEST("unsupported action: " + action, null);
/*    */     }
/*    */     
/* 57 */     Element response = zsc.createElement(AdminConstants.AUTO_PROV_TASK_CONTROL_RESPONSE);
/* 58 */     response.addAttribute("status", result.name());
/* 59 */     return response;
/*    */   }
/*    */   
/*    */   private AutoProvTaskControlResponse.Status handleStart() {
/* 63 */     if (AutoProvisionThread.isRunning()) {
/* 64 */       return AutoProvTaskControlResponse.Status.running;
/*    */     }
/* 66 */     AutoProvisionThread.startup();
/* 67 */     return AutoProvTaskControlResponse.Status.started;
/*    */   }
/*    */   
/*    */   private AutoProvTaskControlResponse.Status handleStatus()
/*    */   {
/* 72 */     if (AutoProvisionThread.isRunning()) {
/* 73 */       return AutoProvTaskControlResponse.Status.running;
/*    */     }
/* 75 */     return AutoProvTaskControlResponse.Status.idle;
/*    */   }
/*    */   
/*    */   private AutoProvTaskControlResponse.Status handleStop()
/*    */   {
/* 80 */     if (AutoProvisionThread.isRunning()) {
/* 81 */       AutoProvisionThread.shutdown();
/* 82 */       return AutoProvTaskControlResponse.Status.stopped;
/*    */     }
/* 84 */     return AutoProvTaskControlResponse.Status.idle;
/*    */   }
/*    */   
/*    */ 
/*    */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*    */   {
/* 90 */     notes.add("Only system admins are allowed.");
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/AutoProvTaskControl.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */